package oj_leetcode;

import java.util.Stack;

public class ValidParentheses {

    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)=='('||s.charAt(i)=='{'||s.charAt(i)=='[') {
                stack.push(s.charAt(i));
            }
            if (s.charAt(i) == ')'||s.charAt(i) == '}'||s.charAt(i) == ']'){
                char top = stack.pop();
                if (top != s.charAt(i)){
                    return false;
                }
            }
        }
        return true;
    }
}
